package com.px.user.mapper;

import com.px.user.entity.Sensi;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface SensiMapper {

    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    @Insert("insert into sensi (txt) values (#{txt})")
    void insert(Sensi sensi);

    @Update("update sensi set txt=#{txt} where id=#{id}")
    void update(Sensi sensi);

    @Delete("delete from sensi where id=#{id}")
    void delete(Integer id);

    @Select("select * from sensi")
    List<Sensi> findAll();

    @Select({"<script>",
            "select * from sensi",
            "<where>",
            " <if test='id != null'>and id = #{id}</if>",
            " <if test='qstart != null'>and createTime >= #{qstart}</if>",
            " <if test='qend != null'>and createTime <![CDATA[<=]]> #{qend}</if>",
            " <if test='txt != null'>and txt like #{txt}</if>",
            "</where>",
            "order by ${orderField} desc limit #{startIndex},#{limit}",
            "</script>",
    })
    List<Sensi> paging(Sensi sensi);

    @Select({"<script>",
            "select count(1) from sensi",
            "<where>",
            " <if test='id != null'>and id = #{id}</if>",
            " <if test='qstart != null'>and createTime >= #{qstart}</if>",
            " <if test='qend != null'>and createTime <![CDATA[<=]]> #{qend}</if>",
            " <if test='txt != null'>and txt like #{txt}</if>",
            "</where>",
            "</script>",
    })
    Integer pagingCount(Sensi sensi);
}
